import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Test {


    public static final String[] SUITS={"♠","♥","♣","♦"};

    //买一副新牌
    public static List<Card> buyCard(){
        List<Card> list=new ArrayList<>();

        for(int i=0;i<4;i++){
            for(int j=1;j<=13;j++){
                Card card=new Card(j,SUITS[i]);
                list.add(card);
            }
        }
        return list;

    }


    //洗牌
    //生成随机数，随机值与i交换

    public static void shuffle(List<Card> cardList){
        for(int i=cardList.size()-1;i>0;i--){

            Random random=new Random();
            int index=random.nextInt(i);//生成一个[0,i)之间的随机值
            swap(cardList,index,i);

        }
        System.out.println(cardList);
    }
    public static void swap(List<Card> cardList,int index,int i){
        Card temp=cardList.get(index);

        cardList.set(index,cardList.get(i));

        cardList.set(i,temp);


    }


    public static void main(String[] args) {
        System.out.println("买一副牌：");
        List<Card> newCard=buyCard();
        System.out.println(newCard);

        System.out.println("洗牌：");
        shuffle(newCard);

        System.out.println("揭牌：");
        //三个人每一最终各有5张牌
        List<Card> hand0=new ArrayList<>();
        List<Card> hand1=new ArrayList<>();
        List<Card> hand2=new ArrayList<>();

        List<Card> hands=new ArrayList<>();

        for(int i=0;i<5;i++){
            for(int j=0;j<3;j++){
                Card card=newCard.remove(0);
                hands.add(card);
            }
        }

        System.out.println(hands);

    }
}
